<?php
namespace app\admin\controller;

use app\common\controller\AdminBase;
use think\Db;
class Index extends AdminBase
{

    /**
     * @var array 前置操作，这里是检查登录
     */
    protected $beforeActionList = [
        'checkAuth'=>['except'=>'']
    ];
    /**
     * @title 检查登录
     * @description 检查登录
     * @author Admin ldy
     * @param name:token  type:string require:1 default:1 desc:
     * @time 2018/9/19  9:36
     */
    protected function checkAuth(){
        /// 如需登录，调用此方法鉴权
        /// 注解1：如果已经登录，则会获取到uid;否则会直接打印错误信息，不执行下面的代码
        /// 注解2：该方法走的是缓存，不通过数据库检查
        /// 注解3：如果没有token信息，需要调登录接口，重新获取token，并保存，token有效期暂定为30天
        /// 注解4：该类所有方法需要登录鉴权，故预先加载
        $token = $this->checkLogin();
//        var_dump( $token);
        if (!$token){
            $this->redirect('/admin/Login/login',302);
        }

        //用户如果操作了个人的数据，就代表今天签到了
//        Sign::isSignToday($this->uid);
    }
    public function user()
    {
        echo '<br><center>';
        $userCount = Db::table('scj_user')->count();
        $urlCount = Db::table('scj_url_person')->count();
        $re = \app\common\library\YuPust::getPushClientCount();
        $Obj = json_decode($re->getData());
        echo '同时在线人数：'.$Obj->data.'<br>';
//        echo $re->getData();
        echo '一共有 '.$userCount.' 个用户<br>';
        echo '一共有 '.$urlCount.' 条url<br>';
        echo '</center><br>';
        $uid = '20';
        $uidarr = ['23','24','26','27','28','29'];
        $start = '2018-12-12';
        $end = '2018-12-19';

        $len = count($uidarr);
        for ($i=0;$i<$len;$i++){
            echo '用户'.$uidarr[$i].':<br>';
            $result[$i]=\app\common\library\Sign::getUserSignDataNearly($uidarr[$i]);
            echo json_encode($result[$i]).'<br>';
//            $result[$i]=\app\common\library\Sign::getUserSignDataBy($uidarr[$i],$start,$end);
        }
//        $re = \app\common\library\Sign::getUserSignDataBy($uid,$start,$end);
//        echo json_encode($result);


//        return '<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px;} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:) </h1><p> ThinkPHP V5.1<br/><span style="font-size:30px">12载初心不改（2006-2018） - 你值得信赖的PHP框架</span></p></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=64890268" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="eab4b9f840753f8e7"></think>';
    }

//    public function sh(){
//    	// $this->show('sdfds');
//    	$this->debugBegain();
//    	$this->showEnv();
//    	$this->debugEnd();
//    	$this->debugTimeShow();
//    	// var_dump($this->request);
//    	return '';
//    }
}
